package com.tanhua.dubbo.api;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tanhua.dubbo.mappers.UserMapper;
import com.tanhua.model.domain.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class UserApiImpl extends ServiceImpl<UserMapper, User> implements UserApi{

    @Autowired
    private UserMapper userMapper;

    /**
     * 根据手机号查询用户
     * @param mobile
     * @return
     */
    @Override
    public User findByMobile(String mobile) {
        QueryWrapper<User> qw = new QueryWrapper<>();
        qw.eq("mobile",mobile);
        return userMapper.selectOne(qw);
    }

    /**
     * 添加新用户
     * @param user
     * @return  userId
     */
    @Override
    public Long saveUser(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    @Override
    public User isMobileExit(String mobile) {
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(User::getMobile, mobile);
        return userMapper.selectOne(wrapper);
    }

    @Override
    public User findByHuanXinId(String huanxinId) {
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(User::getHxUser, huanxinId);
        return userMapper.selectOne(wrapper);
    }
}
